/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.settlement.entity.carinvoice;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.jeesite.common.entity.DataEntity;
import com.jeesite.common.mybatis.annotation.Column;
import com.jeesite.common.mybatis.annotation.JoinTable;
import com.jeesite.common.mybatis.annotation.Table;
import com.jeesite.common.mybatis.mapper.query.QueryType;
import com.jeesite.modules.base.entity.cars.Tcar;
import com.jeesite.modules.base.entity.customer.Customer;
import com.jeesite.modules.order.entity.serviceorder.ServiceOrder;
import com.jeesite.modules.settlement.entity.customercarcontract.CustomerCarContract;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * 车辆发票Entity
 *
 * @author LV
 * @version 2021-03-09
 */
@Table(name = "t_car_invoice", alias = "a", columns = {
        @Column(name = "car_invoice_id", attrName = "carInvoiceId", label = "车辆发票ID", isPK = true),
        @Column(name = "car_invoice_code", attrName = "carInvoiceCode", label = "车辆发票编码"),
        @Column(name = "service_order_id", attrName = "serviceOrder.serviceOrderId", label = "服务订单"),
        @Column(name = "source_from", attrName = "customerCarCon.customerCarContractId", label = "来源自"),
        @Column(name = "customer_id", attrName = "customer.customerId", label = "客户"),
        @Column(name = "date", attrName = "date", label = "发票日期"),
        @Column(name = "invoice_item", attrName = "invoiceItem", label = "开票项目", isQuery = false),
        @Column(name = "invoice_number", attrName = "invoiceNumber", label = "税控发票号", queryType = QueryType.LIKE),
        @Column(name = "frame_number", attrName = "frameNumber", label = "车架号", isQuery = false),
        @Column(name = "car_id", attrName = "tcar.carId", label = "车辆", isQuery = false),
        @Column(name = "tax_rate", attrName = "taxRate", label = "税率", isQuery = false),
        @Column(name = "tax_amount", attrName = "taxAmount", label = "含税金额", isQuery = false),
        @Column(name = "untax_amount", attrName = "untaxAmount", label = "不含税金额", isQuery = false),
        @Column(name = "tax", attrName = "tax", label = "税额", isQuery = false),
        @Column(name = "remarks", attrName = "remarks", label = "备注信息", isQuery = false),
        @Column(name = "create_by", attrName = "createBy", label = "创建者", isUpdate = false),
        @Column(name = "create_date", attrName = "createDate", label = "创建时间", isUpdate = false),
        @Column(name = "update_by", attrName = "updateBy", label = "更新者", isQuery = false),
        @Column(name = "update_date", attrName = "updateDate", label = "更新时间", isQuery = false),
}, joinTable = {
        @JoinTable(type = JoinTable.Type.LEFT_JOIN, entity = ServiceOrder.class, attrName = "serviceOrder", alias = "b",
                on = "b.service_order_id = a.service_order_id",
                columns = {
                        @Column(name = "service_order_id", label = "服务订单ID", isPK = true),
                        @Column(name = "service_order_code", label = "服务订单编号"),
        }),
        @JoinTable(type = JoinTable.Type.LEFT_JOIN, entity = Customer.class, attrName = "customer", alias = "c",
                on = "c.customer_id = a.customer_id", columns = {
                @Column(name = "customer_id", label = "客户编号", isPK = true),
                @Column(name = "customer_name", label = "客户名称"),
        }),
        @JoinTable(type = JoinTable.Type.LEFT_JOIN, entity = CustomerCarContract.class, attrName = "customerCarCon", alias = "d",
                on = "d.customer_car_contract_id = a.source_from", columns = {
                @Column(name = "customer_car_contract_id", label = "客户汽车供需合同ID", isPK = true),
                @Column(name = "customer_car_contract_code", label = "客户汽车供需合同编号"),
        }),
        @JoinTable(type = JoinTable.Type.LEFT_JOIN, entity = Tcar.class, attrName = "tcar", alias = "e",
                on = "e.car_id = a.car_id", columns = {
                @Column(name = "car_id", label = "客户汽车供需合同ID", isPK = true),
                @Column(name = "car_name", label = "客户汽车供需合同编号"),
        }),
}, orderBy = "a.update_date DESC"
)
public class CarInvoice extends DataEntity<CarInvoice> {

    private static final long serialVersionUID = 1L;
    private String carInvoiceId;        // 车辆发票ID
    private String carInvoiceCode;
    private String serviceOrderId;        // 服务订单
    private ServiceOrder serviceOrder;
    private String sourceFrom;        // 来源自
    private CustomerCarContract customerCarCon;
    private String customerId;        // 客户
    private Customer customer;
    private Date date;        // 发票日期
    private String invoiceItem;        // 开票项目
    private String invoiceNumber;        // 税控发票号
    private String frameNumber;        // 车架号
    private String carId;        // 车辆
    private String taxRate;        // 税率
    private Double taxAmount;        // 含税金额
    private Double untaxAmount;        // 不含税金额
    private Double tax;        // 税额
    private Tcar tcar;

    public CarInvoice() {
        this(null);
    }

    public CarInvoice(String id) {
        super(id);
    }

    public String getCarInvoiceId() {
        return carInvoiceId;
    }

    public void setCarInvoiceId(String carInvoiceId) {
        this.carInvoiceId = carInvoiceId;
    }

    @Length(min = 0, max = 64, message = "服务订单长度不能超过 64 个字符")
    public String getServiceOrderId() {
        return serviceOrderId;
    }

    public void setServiceOrderId(String serviceOrderId) {
        this.serviceOrderId = serviceOrderId;
    }

    @Length(min = 0, max = 64, message = "来源自长度不能超过 64 个字符")
    public String getSourceFrom() {
        return sourceFrom;
    }

    public void setSourceFrom(String sourceFrom) {
        this.sourceFrom = sourceFrom;
    }

    @Length(min = 0, max = 64, message = "客户长度不能超过 64 个字符")
    public String getCustomerId() {
        return customerId;
    }

    public void setCustomerId(String customerId) {
        this.customerId = customerId;
    }

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @NotNull(message = "发票日期不能为空")
    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    @Length(min = 0, max = 2, message = "开票项目长度不能超过 2 个字符")
    public String getInvoiceItem() {
        return invoiceItem;
    }

    public void setInvoiceItem(String invoiceItem) {
        this.invoiceItem = invoiceItem;
    }

    @NotBlank(message = "税控发票号不能为空")
    @Length(min = 0, max = 100, message = "税控发票号长度不能超过 100 个字符")
    public String getInvoiceNumber() {
        return invoiceNumber;
    }

    public void setInvoiceNumber(String invoiceNumber) {
        this.invoiceNumber = invoiceNumber;
    }

    @Length(min = 0, max = 100, message = "车架号长度不能超过 100 个字符")
    public String getFrameNumber() {
        return frameNumber;
    }

    public void setFrameNumber(String frameNumber) {
        this.frameNumber = frameNumber;
    }

    @Length(min = 0, max = 64, message = "车辆长度不能超过 64 个字符")
    public String getCarId() {
        return carId;
    }

    public void setCarId(String carId) {
        this.carId = carId;
    }

    @NotBlank(message = "税率不能为空")
    @Length(min = 0, max = 10, message = "税率长度不能超过 10 个字符")
    public String getTaxRate() {
        return taxRate;
    }

    public void setTaxRate(String taxRate) {
        this.taxRate = taxRate;
    }

    @NotNull(message = "含税金额不能为空")
    public Double getTaxAmount() {
        return taxAmount;
    }

    public void setTaxAmount(Double taxAmount) {
        this.taxAmount = taxAmount;
    }

    @NotNull(message = "不含税金额不能为空")
    public Double getUntaxAmount() {
        return untaxAmount;
    }

    public void setUntaxAmount(Double untaxAmount) {
        this.untaxAmount = untaxAmount;
    }

    @NotNull(message = "税额不能为空")
    public Double getTax() {
        return tax;
    }

    public void setTax(Double tax) {
        this.tax = tax;
    }

    public Date getDate_gte() {
        return sqlMap.getWhere().getValue("date", QueryType.GTE);
    }

    public void setDate_gte(Date date) {
        sqlMap.getWhere().and("date", QueryType.GTE, date);
    }

    public Date getDate_lte() {
        return sqlMap.getWhere().getValue("date", QueryType.LTE);
    }

    public void setDate_lte(Date date) {
        sqlMap.getWhere().and("date", QueryType.LTE, date);
    }

    public Date getCreateDate_gte() {
        return sqlMap.getWhere().getValue("create_date", QueryType.GTE);
    }

    public void setCreateDate_gte(Date createDate) {
        sqlMap.getWhere().and("create_date", QueryType.GTE, createDate);
    }

    public Date getCreateDate_lte() {
        return sqlMap.getWhere().getValue("create_date", QueryType.LTE);
    }

    public void setCreateDate_lte(Date createDate) {
        sqlMap.getWhere().and("create_date", QueryType.LTE, createDate);
    }

    public ServiceOrder getServiceOrder() {
        return serviceOrder;
    }

    public void setServiceOrder(ServiceOrder serviceOrder) {
        this.serviceOrder = serviceOrder;
    }

    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public CustomerCarContract getCustomerCarCon() {
        return customerCarCon;
    }

    public void setCustomerCarCon(CustomerCarContract customerCarCon) {
        this.customerCarCon = customerCarCon;
    }

    public String getCarInvoiceCode() {
        return carInvoiceCode;
    }

    public void setCarInvoiceCode(String carInvoiceCode) {
        this.carInvoiceCode = carInvoiceCode;
    }

    public Tcar getTcar() {
        return tcar;
    }

    public void setTcar(Tcar tcar) {
        this.tcar = tcar;
    }
}